package com.iov.fence.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.iov.fence.domain.TbFenceVo;
import com.iov.fence.vo.FenceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.iov.fence.domain.TbFence;
import com.iov.fence.service.ITbFenceService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 围栏信息Controller
 * 
 * @author ruoyi
 * @date 2023-11-15
 */
@RestController
@RequestMapping("/fenceinfo")
public class TbFenceController extends BaseController
{
    @Autowired
    private ITbFenceService tbFenceService;

    /**
     * 查询围栏信息列表
     */
    @RequiresPermissions("fence:fenceinfo:list")
    @GetMapping("/list")
    public TableDataInfo list(TbFence tbFence)
    {
        startPage();
        List<TbFence> list = tbFenceService.selectTbFenceList(tbFence);
        return getDataTable(list);
    }

//    @RequiresPermissions("fence:fenceinfo:listredis")
//    @GetMapping("/listredis")
//    public TableDataInfo listredis(FenceVo fenceVo){
//        TableDataInfo tableDataInfo=tbFenceService.queryListFailure(fenceVo);
//        return tableDataInfo;
//    }
    /**
     * 导出围栏信息列表
     */
    @RequiresPermissions("fence:fenceinfo:export")
    @Log(title = "围栏信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbFence tbFence)
    {
        List<TbFence> list = tbFenceService.selectTbFenceList(tbFence);
        ExcelUtil<TbFence> util = new ExcelUtil<TbFence>(TbFence.class);
        util.exportExcel(response, list, "围栏信息数据");
    }

    /**
     * 获取围栏信息详细信息
     */
    @RequiresPermissions("fence:fenceinfo:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbFenceService.selectTbFenceById(id));
    }

    /**
     * 新增围栏信息
     */
    @RequiresPermissions("fence:fenceinfo:add")
    @Log(title = "围栏信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbFence tbFence)
    {
        return toAjax(tbFenceService.insertTbFence(tbFence));
    }

    /**
     * 修改围栏信息
     */
    @RequiresPermissions("fence:fenceinfo:edit")
    @Log(title = "围栏信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbFence tbFence)
    {
        return toAjax(tbFenceService.updateTbFence(tbFence));
    }

    /**
     * 删除围栏信息
     */
    @RequiresPermissions("fence:fenceinfo:remove")
    @Log(title = "围栏信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbFenceService.deleteTbFenceByIds(ids));
    }

    @RequiresPermissions("fence:fenceinfo:addCoordinate")
    @Log(title = "添加围栏地址",businessType = BusinessType.INSERT)
    @PostMapping("/addcoordinate")
    public AjaxResult addCoordinate(@RequestBody TbFenceVo tbFenceVo){
        TbFence tbFence = new TbFence();
        tbFence.setFenceCoordinate(tbFenceVo.getPath());
        tbFence.setId(tbFenceVo.getId());
        return toAjax(tbFenceService.addCoordinate(tbFence));
    }
}
